package org.hughie.common;

import org.hughie.sync.FundSyncTask;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.stereotype.Component;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author hughie.cheng
 * @date 2024/3/6
 */

@Component
public class SyncHandlerFactory implements BeanPostProcessor {

    private final Map<String, FundSyncTask> fundSyncMap = new ConcurrentHashMap<>();

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        if (bean instanceof FundSyncTask fundSyncTask) {
            fundSyncMap.put(fundSyncTask.getTaskCode(), fundSyncTask);
        }
        return null;
    }

    public FundSyncTask getHandler(String name){
        return fundSyncMap.get(name);
    }
}
